package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRolePower;
import com.ruoyi.system.service.ISysRolePowerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职权和角色关联Controller
 * 
 * @author ruoyi
 * @date 2022-02-12
 */
@RestController
@RequestMapping("/system/power")
public class SysRolePowerController extends BaseController
{
    @Autowired
    private ISysRolePowerService sysRolePowerService;

    /**
     * 查询职权和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:power:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRolePower sysRolePower)
    {
        startPage();
        List<SysRolePower> list = sysRolePowerService.selectSysRolePowerList(sysRolePower);
        return getDataTable(list);
    }

    /**
     * 导出职权和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:power:export')")
    @Log(title = "职权和角色关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysRolePower sysRolePower)
    {
        List<SysRolePower> list = sysRolePowerService.selectSysRolePowerList(sysRolePower);
        ExcelUtil<SysRolePower> util = new ExcelUtil<SysRolePower>(SysRolePower.class);
        return util.exportExcel(list, "power");
    }

    /**
     * 获取职权和角色关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:power:query')")
    @GetMapping(value = "/{recNo}")
    public AjaxResult getInfo(@PathVariable("recNo") String recNo)
    {
        return AjaxResult.success(sysRolePowerService.selectSysRolePowerById(recNo));
    }

    /**
     * 新增职权和角色关联
     */
    @PreAuthorize("@ss.hasPermi('system:power:add')")
    @Log(title = "职权和角色关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRolePower sysRolePower)
    {
        return toAjax(sysRolePowerService.insertSysRolePower(sysRolePower));
    }

    /**
     * 修改职权和角色关联
     */
    @PreAuthorize("@ss.hasPermi('system:power:edit')")
    @Log(title = "职权和角色关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRolePower sysRolePower)
    {
        return toAjax(sysRolePowerService.updateSysRolePower(sysRolePower));
    }

    /**
     * 删除职权和角色关联
     */
    @PreAuthorize("@ss.hasPermi('system:power:remove')")
    @Log(title = "职权和角色关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recNos}")
    public AjaxResult remove(@PathVariable String[] recNos)
    {
        return toAjax(sysRolePowerService.deleteSysRolePowerByIds(recNos));
    }
}
